home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / tcl / expecTerm / termfuncs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-17  |  22.8 KB  |  791 lines  |  [TEXT/MPS ]

  1. /* termfuncs.c
  2. ***************************************************************************** 
  3. expecTerm version 1.0 beta
  4. Mark Weissman
  5. Christopher Matheus
  6. Copyright 1992 by GTE Laboratories Incorporated.
  7.  
  8. Portions of this work are in the public domain.  Permission to use,
  9. copy, modify, and distribute this software and its documentation for
  10. any purpose and without fee is hereby granted, provided that the above
  11. copyright notice appear in all copies and that both the copyright
  12. notice and warranty disclaimer appear in supporting documentation, and
  13. that the names of GTE Laboratories or any of their entities not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.
  16.  
  17. GTE disclaims all warranties with regard to this software, including
  18. all implied warranties of merchantability and fitness for a particular
  19. purpose, even if GTE Laboratories Incorporated knows about the
  20. purpose.  In no event shall GTE be liable for any special, indirect or
  21. consequential damages or any damages whatsoever resulting from loss of
  22. use, data or profits, whether in an action of contract, negligence or
  23. other tortuous action, arising out of or in connection with the use or
  24. performance of this software.
  25.  
  26. This code is based on and may include parts of Don Libes' expect code:
  27.   expect written by: Don Libes, NIST, 2/6/90
  28.   Design and implementation of expect was paid for by U.S. tax
  29.   dollars.  Therefore it is public domain.  However, the author and NIST
  30.   would appreciate credit if this program or parts of it are used.
  31. ******************************************************************************
  32.  
  33. Written by: Mark Weissman 9/92
  34. */
  35.  
  36.  
  37. #include "win.h"
  38. #include "termfuncs.h"
  39. #define ARGTIMES(FORM) \
  40. { switch(Argno) { \
  41.   case 0: Arg[0]=1; \
  42.   case 1: while(Arg[0]--) {  FORM; } \
  43.   } \
  44. }
  45.  
  46. #define ARGCOUNT ((Argno==0)?1:Arg[0])
  47.  
  48. long Arg[MAXTERMARG], Argno=0, Vars[MAXTERMVAR];
  49.  
  50. void do_nothing()            {}
  51.  
  52. void do_CRNL_on()            {Session->crnlp = 0;}
  53. void do_CRNL_off()            {Session->crnlp = 1;}
  54.  
  55. void do_TABSPACE_on()            {Session->tabspacep = 0;}
  56. void do_TABSPACE_off()            {Session->tabspacep = 1;}
  57.  
  58. void do_ECHO_on()            {Session->echop = 0;}
  59. void do_ECHO_off()            {Session->echop = 1;}
  60.  
  61. void do_protect()            {wattron(Session->win,A_PROTECT);}
  62. void do_noprotect()             {wattroff(Session->win,A_PROTECT);}
  63.  
  64. void do_bold()                 {wattron(Session->win,A_BOLD);}
  65. void do_nobold()             {wattroff(Session->win,A_BOLD);}
  66.  
  67. void do_reverse()             {wattron(Session->win,A_REVERSE);}
  68. void do_noreverse()             {wattroff(Session->win,A_REVERSE);}
  69.  
  70. void do_dim()                 {wattron(Session->win,A_DIM);}
  71. void do_nodim()             {wattroff(Session->win,A_DIM);}
  72.  
  73. void do_underline()             {wattron(Session->win,A_UNDERLINE);}
  74. void do_nounderline()             {wattroff(Session->win,A_UNDERLINE);}
  75.  
  76. void do_blink()             {wattron(Session->win,A_BLINK);}
  77. void do_noblink()             {wattroff(Session->win,A_BLINK);}
  78.  
  79. void do_invisible()             {wattron(Session->win,A_INVIS);}
  80. void do_noinvisible()             {wattroff(Session->win,A_INVIS);}
  81.  
  82. void do_altcharset()             {wattron(Session->win,A_ALTCHARSET);}
  83. void do_noaltcharset()             {wattroff(Session->win,A_ALTCHARSET);}
  84.  
  85. void do_standout()             {wattron(Session->win,A_STANDOUT);}
  86. void do_nostandout()             {wattroff(Session->win,A_STANDOUT);}
  87.  
  88. void do_normal()
  89. {
  90. /*  if (Session->win->_attrs & A_STANDOUT) wstandend(Session->win); */
  91.   wattrset(Session->win,A_NORMAL); 
  92. }
  93.  
  94. void do_sgr()
  95. {
  96.   do_normal();
  97.   if ((Argno >= 1) && Arg[0]) do_standout();
  98.   if ((Argno >= 2) && Arg[1]) do_underline();
  99.   if ((Argno >= 3) && Arg[2]) do_reverse();
  100.   if ((Argno >= 4) && Arg[3]) do_blink();
  101.   if ((Argno >= 5) && Arg[4]) do_dim();
  102.   if ((Argno >= 6) && Arg[5]) do_bold();
  103.   if ((Argno >= 7) && Arg[6]) do_invisible();
  104.   if ((Argno >= 8) && Arg[7]) do_protect();
  105.   if ((Argno >= 9) && Arg[8]) do_altcharset();
  106. }
  107.  
  108. void do_VTModes()
  109. {
  110.   int i;
  111.   for (i=0; i < (Argno?Argno:1); ++i)
  112.     switch (Arg[i]) {
  113.     case 0: do_normal(); break;
  114.     case 1: do_bold(); break;
  115.     case 4: do_underline(); break;
  116.     case 5: do_blink(); break;
  117.     case 7: do_standout(); break;
  118.     }
  119. }
  120.  
  121. void do_cursor_invisible()         {curs_set(0);}
  122. void do_cursor_normal()         {curs_set(1);}
  123. void do_cursor_brighter()         {curs_set(2);}
  124.  
  125. void do_start_keypad()             {keypad(Session->win,TRUE);}
  126. void do_stop_keypad()             {keypad(Session->win,FALSE);}
  127.  
  128. void do_enter_xon_xoff_mode()         {}
  129. void do_exit_xon_xoff_mode()         {}
  130.  
  131. void do_enter_meta_mode()         {meta(Session->win,TRUE);}
  132. void do_exit_meta_mode()         {meta(Session->win,FALSE);}
  133.  
  134. void do_enter_insert_mode()         {Session->term->InsertMode=1;}
  135. void do_exit_insert_mode()         {Session->term->InsertMode=0;}
  136.  
  137. void do_enter_delete_mode()         {}
  138. void do_exit_delete_mode()         {}
  139.  
  140. void do_set_left_margin()         {Session->lmarg = Arg[0];}
  141. void do_set_right_margin()         {Session->rmarg = Arg[0];}
  142.  
  143. void do_enter_automatic_margin_mode()    {}
  144. void do_exit_automatic_margin_mode()     {}
  145. void do_clear_soft_margins()         {Session->lmarg = 0; Session->rmarg = Session->columns; }
  146.  
  147. void do_set_window () {}
  148. void do_print_screen () {}
  149. void do_printer_on () {}
  150. void do_printer_off () {}
  151. void do_print_nbytes () {}
  152.  
  153. void do_disable_soft_labels()         {
  154.   Session->term->bool_labels = 0;
  155. }
  156. void do_enable_soft_labels()         {
  157.   Session->term->bool_labels = 1;
  158. }
  159. void do_program_label() {/* Program label #1 to show string #2 */
  160.   if (Argno > 0 && Arg[0] >= 0 && Arg[0] <= 10) {
  161.     char **lfptr, *olf;
  162.     
  163.     lfptr = (char **)&(Session->term->str_lf0) + Arg[0];
  164.     olf   = *((char **)&(Session->termOriginal->str_lf0) + Arg[0]);
  165.       
  166.     if (*lfptr != olf && *lfptr > (char *)0) free(*lfptr);
  167.     
  168.     if (Argno > 1 && Arg[1] > 0) {
  169.       *lfptr = (char *)malloc(strlen((char *)Arg[1])+2);
  170.       strcpy(*lfptr,(char *)Arg[1]);
  171.     }
  172.     else {
  173.       *lfptr = (char *)Strdup(" ");
  174.       **lfptr = '\0';
  175.     }
  176.     (*lfptr)[strlen(*lfptr)+1] = 's'; /* Hide Type info after string */
  177.     if (Arg[0] > 0) {
  178.       int n = Arg[0] - 1;
  179.       static int lpos[] = {0, 9, 18, 27, 45, 54, 63, 72};
  180.       int oattrs = Session->win->_attrs;
  181.       char template[32], lbuf[XMAX], *lptr=lbuf;
  182.       int lh = Session->term->int_lh, lw = Session->term->int_lw, nlab = Session->term->int_nlab;
  183.       int l, space, x, y;
  184.       int ox = Session->x, oy = Session->y;
  185.     
  186.       memset(lbuf,' ',XMAX);
  187.       strncpy(lbuf,(char *)Arg[1], strlen((char *)Arg[1]));
  188.       
  189.       if (lh <= 0) lh = 1;
  190.       if (lw <= 0) lw = 8;
  191.       if (nlab <= 0) nlab = 8;
  192.       space = Session->columns - nlab*lw;
  193.       sprintf(template,"%%-%ds", lw);
  194.       x = (nlab==8 && lw == 8) ? lpos[n] : ((lw*n) + ((nlab>=2)?((n*space) / (nlab-1)):0));
  195.       do_normal();
  196.       do_standout();
  197.       for(l=lh;l > 0;--l) {
  198.     *(lptr=(lbuf+(l*lw)))='\0';
  199.     y = (Session->rows - (lh-l+1));
  200.     lptr -= lw;
  201.     mvwprintw(Session->win, y, x, template, lptr);
  202.     *lptr = '\0';
  203.       }
  204.       wattrset(Session->win, oattrs);
  205.       do_normal();        /* I'm not sure this should reset attributes */
  206.       wmove(Session->win, oy, ox);
  207.     }
  208.   }
  209. }
  210. void do_program_xmit() { /* Program funct key #1 to transmit string #2 */
  211.   if (Argno > 0 && Arg[0] >= 0 && Arg[0] <= 10) {
  212.     char **kfptr, *okf;
  213.     
  214.     kfptr = (char **)&(Session->term->str_kf0) + Arg[0];
  215.     okf   = *((char **)&(Session->termOriginal->str_kf0) + Arg[0]);
  216.  
  217.     if (*kfptr != okf && (int)*kfptr > 0) free(*kfptr);
  218.     
  219.     if (Argno > 1 && Arg[1] > 0) {
  220.       *kfptr = (char *)malloc(strlen((char *)Arg[1])+2);
  221.       strcpy(*kfptr,(char *)Arg[1]);
  222.     }
  223.     else {
  224.       *kfptr = (char *)Strdup(" ");
  225.       **kfptr = '\0';
  226.     }
  227.     /* The 'X' below is what tells the function key to transmit this string!!! */
  228.     (*kfptr)[strlen(*kfptr)+1] = 'X'; /* Hide Type info after string */
  229.   }
  230. }
  231. void do_program_type() {/*Program funct key #1 to type string #2*/
  232.   if (Argno > 0 && Arg[0] >= 0 && Arg[0] <= 10) {
  233.     char **kfptr, *okf;
  234.     
  235.     kfptr = (char **)&(Session->term->str_kf0) + Arg[0];
  236.     okf   = *((char **)&(Session->termOriginal->str_kf0) + Arg[0]);
  237.  
  238.     if (*kfptr != okf && (int)*kfptr > 0) free(*kfptr);
  239.     
  240.     if (Argno > 1 && Arg[1] > 0) {
  241.       *kfptr = (char *)malloc(strlen((char *)Arg[1])+2);
  242.       strcpy(*kfptr,(char *)Arg[1]);
  243.     }
  244.     else {
  245.       *kfptr = (char *)Strdup(" ");
  246.       **kfptr = '\0';
  247.     }
  248.     /* The 'T' below is what tells the function key to type this string!!! */
  249.     (*kfptr)[strlen(*kfptr)+1] = 'T'; /* Hide Type info after string */
  250.   }
  251. }
  252. void do_program_local() {  /* Program funct key #1 to execute string #2 */
  253.   if (Argno > 0 && Arg[0] >= 0 && Arg[0] <= 10) {
  254.     char **kfptr, *okf;
  255.     
  256.     kfptr = (char **)&(Session->term->str_kf0) + Arg[0];
  257.     okf   = *((char **)&(Session->termOriginal->str_kf0) + Arg[0]);
  258.  
  259.     if (*kfptr != okf && (int)*kfptr > 0) free(*kfptr);
  260.     
  261.     if (Argno > 1 && Arg[1] > 0) {
  262.       *kfptr = (char *)malloc(strlen((char *)Arg[1])+2);
  263.       strcpy(*kfptr,(char *)Arg[1]);
  264.     }
  265.     else {
  266.       *kfptr = (char *)Strdup(" ");
  267.       **kfptr = '\0';
  268.     }
  269.     /* The 'L' below is what tells the function key to locally type this string!!! */
  270.     (*kfptr)[strlen(*kfptr)+1] = 'L'; /* Hide Type info after string */
  271.   }
  272. }
  273.  
  274. void do_enable_altchar_mode()     {}
  275. void do_disable_altchar_mode()     {}
  276.  
  277. void do_request_for_input()         {}
  278.  
  279. void do_underline_char()         {}
  280.  
  281. void do_display_status()         {}
  282. void do_go_to_status()             {}
  283. void do_return_from_status()         {}
  284. void do_nodisplay_status()         {}
  285.  
  286. void do_cursor_down_half_line()     {}
  287. void do_cursor_up_half_line()         {}
  288.  
  289. void do_wrap()                 {Session->wrap = 1;}
  290. void do_nowrap()             {Session->wrap = 0;}
  291.  
  292. void do_enter_cursor_addressing_mode()     {Session->crnlp = 1;}
  293. void do_exit_cursor_addressing_mode()     {Session->crnlp = 0;}
  294. void do_curse_up()             { Go((Session->y)-ARGCOUNT,(Session->x));}
  295. void do_curse_down()            { Go((Session->y)+ARGCOUNT,(Session->x));}
  296. void do_curse_forward()            {
  297.   if (Session->term->Local) {
  298.     int n = ARGCOUNT;
  299.     if ((Session->x + n) >= (Session->columns - 1)) {
  300.       n = (Session->columns - Session->x - 1);
  301.       do_bell();
  302.       Go(Session->y, Session->x+n);
  303.     }
  304.   }
  305.   else if (Session->term->bool_xhp==1) {
  306.     char c;
  307.     /* standout not erased by overwriting */ /* This is probably the wrong flag */
  308.     ARGTIMES(BPUTC(Session, (c=charyx(Session->y, Session->x))?c:' '));
  309.   }
  310.   else {
  311.     ARGTIMES(Go((Session->y),(Session->x)+1));
  312.   }
  313. }
  314. void do_curse_back() { 
  315.   Go((Session->y),(Session->x-ARGCOUNT));
  316.   if (Session->term->Local) {
  317.     if (attryx(Session->y, Session->x) != 'P') NextField(-1);
  318.     { int ox = Session->x, oy = Session->y;
  319.       BPUTC(Session,' ');
  320.       Go(oy, ox);
  321.     }
  322.   }
  323. }
  324. void do_scroll_left()             {}
  325. void do_scroll_right()             {}
  326. void do_scroll_reverse()        {
  327.   int n = ARGCOUNT;
  328.   if (Session->term->Local) {
  329.     if ((Session->y - n) < YMIN) {
  330.       do_bell();
  331.       n = Session->y;
  332.     }
  333.   }
  334.   Go((Session->y)-n,(Session->x));
  335. }
  336. void do_scroll_forward()        { 
  337.   int n = ARGCOUNT;
  338.   if (Session->term->Local) {
  339.     if ((Session->y + n) >= Session->rows) {
  340.       do_bell();
  341.       n = Session->rows - Session->y - 1;
  342.     }
  343.   }
  344.   if (Session->crnlp) 
  345.     Go((Session->y)+n,(Session->x));
  346.   else Go((Session->y)+n,XMIN); 
  347. }
  348. void do_newline(){
  349.   extern char *OutputSequence;
  350.   if (Session->crnlp && (*OutputSequence != '\r')) Go((Session->y)+ARGCOUNT,(Session->x));
  351.   else Go((Session->y)+ARGCOUNT,XMIN);
  352. }
  353. void do_set_cursor()
  354. {
  355.   long nx=XMIN, ny=YMIN;
  356.   /*CacheInput();*/ 
  357.   switch (Argno) {
  358.   case 2: if (Arg[1]) nx=((Arg[1]>0)?Arg[1]:0);
  359.   case 1: if (Arg[0]) ny=((Arg[0]>0)?Arg[0]:0);
  360.   }
  361.   Go(ny,nx);
  362. }
  363. void do_home() {
  364.   Go(YMIN,XMIN);
  365.   if (Session->term->Local) NextField(0);
  366. }
  367. void do_set_cursor_column()         { 
  368.   if (Arg[0] > Session->x && (Session->term->bool_xhp==1)) {
  369.     /* Propogate Attribute */
  370.     int x=Session->x, y=Session->y;
  371.     char c;
  372.     for (x=Session->x; x<Arg[0]; ++x) mvwaddch(Session->win, y, x, ((c=charyx(y,x))?c:' '));
  373.   }
  374.   Go((Session->y),Arg[0]);
  375. }
  376. void do_set_cursor_row()         { 
  377.   Go(Arg[0],(Session->x));
  378. }
  379. void do_save_cursor()             {Session->save_x = (Session->x); Session->save_y = (Session->y);}
  380. void do_restore_cursor()         { Go(Session->save_y,Session->save_x);}
  381. void do_carriage_return()
  382. {
  383.   /* Comment out smart version.  If you need \r\n to \n mapping use ExpectCap entry */
  384.   if (Session->term->Local) {
  385.     int op=0, x, y;
  386.     char fieldsep = (char)31, blockterm = (char)30;
  387.     char fbuf[BUFSIZ], *b=fbuf;
  388.     if (Session->win->_y) {
  389.       for(y=0; y < Session->rows; ++y) {
  390.     if (Session->win->_y[y]) {
  391.       for (x=0; x < Session->columns; ++x) {
  392.         int np = (attryx(y,x) == 'P');
  393.         if (!op && np && b != fbuf) {
  394.           if (Session->term->bool_hpFormatMode==1) *b++ = fieldsep;
  395.           else {
  396.         *b++ = '\r';
  397.         if (Session->term->bool_hpAutoLinefeed==1) *b++ = '\n';
  398.           }
  399.         }
  400.         if (np) *b++ = charyx(y,x);
  401.         op = np;
  402.       }
  403.     }
  404.       }
  405.     }
  406.     if (b != fbuf && (Session->term->bool_hpFormatMode!=1)) *b++ = '\r';
  407.     *b++ = blockterm;
  408.     *b = '\0';
  409.     write(Session->fd, fbuf, b-fbuf);
  410.   }
  411.   else Go((Session->y),XMIN); 
  412. }
  413. void do_set_tab_stop()             {Session->tabs[Session->x] = 1;}
  414. void do_clear_tab()             {Session->tabs[Session->x] = 0;}
  415. void do_clear_tabs()             {long i; for (i = 0; i<Session->columns; i++) Session->tabs[i] = 0;}
  416. void do_backtab()             {
  417.   if (Session->term->Local) {
  418.     long y=Session->y, x=Session->x;
  419.     for(;attryx(y, x-1) == 'P'; --x);
  420.     if (x != Session->x) Go(y,x);
  421.     else {
  422.       Go(y,x);
  423.       NextField(-1);
  424.       y=Session->y, x=Session->x;
  425.       for(;attryx(y, x-1) == 'P'; --x);
  426.       Go(y,x);
  427.     }
  428.   }
  429. }
  430. void do_tab()
  431. {
  432.   if (Session->term->Local) {
  433.     NextField((attryx(Session->y,Session->x)=='P'));
  434.   }
  435.   else if (Session->tabspacep) {
  436.     for (BPUTC(Session,' '); !Session->tabs[(Session->x)];BPUTC(Session,' '));
  437.   }
  438.   else for (Go((Session->y),(Session->x+1)); !Session->tabs[Session->x];Go((Session->y),(Session->x+1)));
  439. }
  440. void do_font0()         {wattrset(Session->win,A_NORMAL);}
  441. void do_font1()         {wattrset(Session->win,A_ALTCHARSET);}
  442. void do_font2()         {}
  443. void do_font3()         {}
  444. void do_font4()         {}
  445. void do_font5()         {}
  446. void do_font6()         {}
  447. void do_font7()         {}
  448.  
  449. void do_bell()             {beep();}
  450. void do_visible_bell()         {}
  451.  
  452. void do_lower_left()         {}
  453.  
  454. void do_formfeed()         {}
  455.  
  456. void do_clear_to_eos()         { 
  457.   if (Session->term->Local) {
  458.     int ox = Session->x, oy = Session->y, x=ox, y=oy;
  459.     int oattrs = Session->win->_attrs;
  460.     for(; y < Session->rows; ++y, x=0)
  461.       for(; x < Session->columns; ++x)
  462.     if (attryx(y,x) == 'P') {
  463.       wattrset(Session->win, (Session->win->_y[y][x] & A_ATTRIBUTES));
  464.       mvwaddch(Session->win,y,x,' ');
  465.     }
  466.     wattrset(Session->win, oattrs);
  467.     Go(oy, ox);
  468.   }
  469.   else wclrtobot(Session->win);
  470. }
  471. void do_clear_to_bos()
  472. {                /* clr to bos */
  473.   if (Session->term->Local) {
  474.     int ox = Session->x, oy = Session->y, x=ox, y=oy;
  475.     int oattrs = Session->win->_attrs;
  476.     for(; y >= YMIN; --y, x=Session->rows-1)
  477.       for(; x >= XMIN; --x)
  478.     if (attryx(y,x) == 'P') {
  479.       wattrset(Session->win, (Session->win->_y[y][x] & A_ATTRIBUTES));
  480.       mvwaddch(Session->win,y,x,' ');
  481.     }
  482.     wattrset(Session->win, oattrs);
  483.     Go(oy, ox);
  484.   }
  485.   else {
  486.     long oy=(Session->y), ox=(Session->x), yy, xx;
  487.    
  488.     Go(YMIN,XMIN);        /* Allow for cache input */
  489.     for (yy=0; yy<oy; ++yy) {
  490.       wmove(Session->win, yy, 0);
  491.       wclrtoeol(Session->win);
  492.     }
  493.     for(xx=0; xx<ox; ++xx) wdelch(Session->win);
  494.     Go(oy,XMIN);
  495.   }
  496. }
  497. void do_clear_to_eol()         { 
  498.   if (Session->term->Local) {
  499.     int x = Session->x, ox=x, y = Session->y, oy=y;
  500.     while (attryx(y,x) == 'P') { BPUTC(Session,' '); ++x; }
  501.     Go(oy, ox);
  502.   }
  503.   else wclrtoeol(Session->win);
  504. }
  505.  
  506. void do_clear_to_bol()
  507. {
  508.   if (Session->term->Local) {
  509.     int x = Session->x, y = Session->y;
  510.     while (attryx(y,x) == 'P') --x;
  511.     while (attryx(y,++x) == 'P') BPUTC(Session,' ');
  512.     while (attryx(y,x) == 'P') --x;
  513.     Go(Session->y, x+1);
  514.   }
  515.   else {
  516.     long ox=Session->x;
  517.     Go((Session->y),XMIN); 
  518.     while (ox--) wdelch(Session->win);
  519.   }
  520. }
  521.  
  522. void do_clear()
  523. {
  524.   do_home();
  525.   do_clear_to_eos();
  526. }
  527.  
  528. void do_clear_line()
  529. {
  530.   if (Session->term->Local) {
  531.     int ox = Session->x, oy = Session->y;
  532.     Go(oy, XMIN);
  533.     NextField(0);
  534.     while (Session->y == oy) BPUTC(Session, ' ');
  535.     Go(oy, ox);
  536.   }
  537.   else {
  538.     Go((Session->y),XMIN);
  539.     wclrtoeol(Session->win); 
  540.   }
  541. }
  542.  
  543. void do_erase_chars()
  544. {
  545.   long dx;
  546.    
  547.   BFLUSH(1);
  548.   for (dx=(Session->x)+Arg[0]-1; dx>=Session->x; --dx) mvwaddch(Session->win,(Session->y),dx,' ');
  549.   wmove(Session->win,(Session->y),(Session->x));
  550. }
  551.  
  552. void do_delete_chars() { 
  553.    
  554.   BFLUSH(1); /* Last chance to look before deleting */
  555.   ARGTIMES(wdelch(Session->win)); 
  556. }
  557.  
  558. void do_insert_chars()
  559. { long ox=(Session->x), oy=(Session->y);
  560.    
  561.   BFLUSH(1); /* last chance to look at buffer before clobbering */
  562.   ARGTIMES(winsch(Session->win,' '));
  563.   wmove(Session->win,oy,ox);
  564. }
  565.  
  566. void do_repeat_char()         { ARGTIMES(BPUTC(Session, (char)Arg[1])); }
  567.  
  568. void do_set_scroll_region()
  569. {
  570.   if (!Argno) Arg[0]=YMIN, Arg[1]=(Session->rows-1); 
  571.   wsetscroll(Session,Arg[0],Arg[1]);
  572. }
  573.  
  574. /* do_reset - Reset emulator and screen
  575.  */
  576. void do_reset()
  577. {
  578.   register long i;
  579.  
  580.    
  581.   Session->wrap = 1;
  582.   Session->save_y = YMIN-1;        /* So we know we haven't saved */
  583.   for (i=XMIN; i<Session->columns; i++) Session->tabs[i] = ((i/8)*8 == i);
  584.   wsetscroll(Session,YMIN,(Session->rows-1));
  585.   BFLUSH(1); /* Flush old Buffer before clearing screen */
  586.   (Session->x)=XMIN;
  587.   (Session->y)=YMIN;
  588.   do_clear();
  589.   do_normal();
  590.   wmove(Session->win, (Session->x), (Session->y));
  591. }
  592.  
  593. /* The following are routines for VT102 compatibility
  594.  */
  595.  
  596. void do_insert_line()
  597. {
  598.   long oy, ox;
  599.   CacheInput();
  600.   BFLUSH(1); /* Flush line to be replaced with insert */
  601.   getyx(Session->win,oy,ox);
  602.   ARGTIMES( {
  603.     if (BMARG(Session) < (Session->rows-1)) {
  604.       wmove(Session->win,BMARG(Session),0);
  605.       wdeleteln(Session->win);
  606.       wmove(Session->win,oy,ox);
  607.     }
  608.     winsertln(Session->win);
  609.   });
  610. }
  611.  
  612.  
  613. void do_delete_line()
  614. {
  615.   long oy, ox;
  616.   CacheInput();
  617.   BFLUSH(1); /* Flush line to be deleted */
  618.   getyx(Session->win,oy,ox);
  619.   ARGTIMES( {
  620.     wdeleteln(Session->win);
  621.     if (BMARG(Session) < (Session->rows-1)) {
  622.       wmove(Session->win,BMARG(Session),0);
  623.       winsertln(Session->win);
  624.       wmove(Session->win,oy,ox);
  625.     }});
  626. }
  627.  
  628.  
  629. void do_HPDC2() {
  630.   Session->term->bool_hpInhibitDC2 = (Arg[0]&&1);
  631. }
  632. void do_HPSHAKE() {
  633.   Session->term->bool_hpInhibitHandshake = (Arg[0]&&1);
  634. }
  635. void do_HPXMITFUNS() {
  636.   Session->term->bool_hpTransmitFuns = (Arg[0]&&1);
  637. }
  638. void do_HPSPOW() {
  639.   Session->term->bool_hpSPOW = (Arg[0]&&1);
  640. }
  641. void do_HPEOLWRAP() {
  642.   Session->term->bool_hpInhibitEOLWrap = (Arg[0]&&1);
  643. }
  644. void do_HPAUTOKBDLOCK() {
  645.   Session->term->bool_hpAutoKbdLock = (Arg[0]&&1);
  646. }
  647. void do_HPAUTOLINEFEED() {
  648.   Session->term->bool_hpAutoLinefeed = (Arg[0]&&1);
  649. }
  650. void do_HPCAPSLOCK() {
  651.   Session->term->bool_hpCapsLock = (Arg[0]&&1);
  652. }
  653. void do_HPAUTOTERM() {
  654.   Session->term->bool_hpAutoTerm = (Arg[0]&&1);
  655. }
  656. void do_HPCLEARTERM() {
  657.   Session->term->bool_hpClearTerm = (Arg[0]&&1);
  658. }
  659. void do_HPKBDLOCK() {
  660.   Session->term->bool_hpKbdLock = 1;
  661. }
  662. void do_HPKBDUNLOCK() {
  663.   Session->term->bool_hpKbdLock = 0;
  664. }
  665. void do_HPMEMLOCK() {
  666.   Session->term->bool_hpMemLock = 1;
  667. }
  668. void do_HPMEMUNLOCK() {
  669.   Session->term->bool_hpMemLock = 0;
  670. }
  671. void do_HPDISPFUNS() {
  672.   Session->term->bool_hpDispFuns = 1;
  673. }
  674. void do_HPNODISPFUNS() {
  675.   Session->term->bool_hpDispFuns = 0;
  676. }
  677. void do_HPKEYS() {
  678.   Session->term->bool_hpKeys = 1;
  679. }
  680. void do_HPNOKEYS() {
  681.   Session->term->bool_hpKeys = 0;
  682. }
  683. void do_HPATTR() {
  684.   int n = Arg[0] - '@';
  685.   if (Argno > 1 && Arg[1]) n &= 16;
  686.   if (!Argno) return;
  687.   if (n==0) { do_normal(); return; }
  688.   if (n & 1)  do_blink();
  689.   if (n & 2)  do_reverse();
  690.   if (n & 4)  do_underline();
  691.   if (n & 8)  do_dim();
  692.   if (n & 16) do_invisible();
  693. }
  694. void do_HPMODES() {
  695.   if (Arg[0]) Session->term->bool_hpInhibitDC2           = (Arg[0]=='1');
  696.   if (Arg[1]) Session->term->bool_hpInhibitHandshake     = (Arg[1]=='1');
  697.   if (Arg[2]) { if (Arg[2]=='1') do_HPPAGE(); else do_HPNOPAGE(); }
  698.   if (Arg[3]) Session->term->bool_hpInhibitEOLWrap    = (Arg[3]=='1');
  699.   if (Arg[4]) Session->term->bool_hpSPOW         = (Arg[4]=='1');
  700.   if (Arg[5]) Session->term->bool_hpTransmitFuns     = (Arg[5]=='1');
  701.   if (Arg[6]) Session->term->bool_hpAutoTerm         = (Arg[6]=='1');
  702.   if (Arg[7]) Session->term->bool_hpClearTerm         = (Arg[7]=='1');
  703. }
  704. void do_HPSTATUS1() {
  705.   char *status = "\033\\0000000\r\n", *byte = status + 2;
  706.   int wc, cc = strlen(status);
  707.   TermTab *t = Session->term;
  708.   byte[0] = '0' | 0; /* display mem in Kbytes: b3=8k, b2 = 4k, b1=2k, b0 = 1k */
  709.   byte[1] = '0' |((t->bool_hpPageMode==1)<<3)|((t->bool_hpInhibitEOLWrap==1)<<2)|((t->bool_hpSPOW==1)<<1)|(t->bool_hpTransmitFuns==1);
  710.   byte[2] = '0' |((t->bool_hpInhibitDC2==1)<<3)|((t->bool_hpInhibitHandshake==1)<<2);
  711.   byte[3] = '0' |(1<<3)|((t->bool_hpAutoLinefeed==1)<<2)|((t->bool_hpBlockMode==1)<<1)|(t->bool_hpCapsLock==1);
  712.   byte[4] = '0'; /* pending: b3=status2, b2=enter, b1=userfun, b0=cursor-sense */
  713.   byte[5] = '0'; /* errors: b3=p2@rrinter, b2=0, b1=self-test, b0=framing, overrun or parity */
  714.   byte[6] = '0'; /* pending: b3=0, b2=0, b1=DeviceOpStatus, b0=DeviceStatus */
  715.   if ((t->bool_hpBlockMode==1) && (t->bool_hpPageMode==1)) cc -= 2;
  716.   else if (t->bool_hpAutoLinefeed!=1) cc -= 1;
  717.   wc = write(Session->fd,status, cc);
  718. /*  debuglog("HPSTATUS1: Write(%d, \"^[%s\", %d) => %d\r\n", Session->fd, status+1, cc, wc); */
  719. }
  720.  
  721. void do_HPSTATUS2() {
  722.   char *status = "\033|0000000\r\n", *byte = status + 2;
  723.   int wc, cc = strlen(status);
  724.   TermTab *t = Session->term;
  725.   byte[0] = '0'; /* nondisplay mem: b3=8k, b2 = 4k, b1=2k, b0 = 1k */
  726.   byte[1] = '0' |(0<<3)|(1<<2)|(0<<1)|1;
  727.   byte[2] = '0';
  728.   byte[3] = '0';
  729.   byte[4] = '0';
  730.   byte[5] = '0';
  731.   byte[6] = '0' |(0<<3)|(1<<2)|(1<<1)|1; /* b3=0, b2=mem-full, b1=memlock, b0 = not locked in row 0 */
  732.   if ((t->bool_hpBlockMode==1) && (t->bool_hpPageMode==1)) cc -= 2;
  733.   else if (t->bool_hpAutoLinefeed!=1) cc -= 1;
  734.   wc = write(Session->fd,status, cc);
  735. /*  debuglog("HPSTATUS1: Write(%d, \"^[%s\", %d) => %d\r\n", Session->fd, status+1, cc, wc); */
  736. }
  737.  
  738. void do_HPDEVICEID() {
  739.   char *status = "XXXXX\r\n";
  740.   int wc, cc = strlen(status);
  741.   TermTab *t = Session->term;
  742.  
  743.   if (*t->type == 'h') strncpy(status, t->type+2, 5);
  744.   else strncpy(status, t->type, 5);
  745.   if (status[4] == '\0') status[4] = 'B';
  746.  
  747.   if ((t->bool_hpBlockMode==1) && (t->bool_hpPageMode==1)) cc -= 2;
  748.   else if (t->bool_hpAutoLinefeed!=1) cc -= 1;
  749.   wc = write(Session->fd,status, cc);
  750.   /*  debuglog("DEVICEID: write(%d, \"%s\", %d) => %d\r\n", Session->fd, status, cc, wc); */
  751. }
  752.  
  753. static HPSetLocal() {
  754.   Session->term->Local = 
  755.     ((Session->term->bool_hpPageMode==1) 
  756.      && (Session->term->bool_hpBlockMode==1)
  757.      && (Session->term->bool_hpFormatMode==1));
  758. }
  759. void do_HPFORMAT() {
  760.   Session->term->bool_hpFormatMode = 1;
  761.   do_enter_insert_mode();
  762.   HPSetLocal();
  763.   do_clear_tabs();
  764.   Session->lmarg = 0; Session->rmarg = Session->columns;
  765.   Go(YMIN,XMIN);
  766.   NextField(0);
  767. }
  768. void do_HPNOFORMAT() {
  769.   Session->term->bool_hpFormatMode = 0;
  770.   do_enter_insert_mode();
  771.   HPSetLocal();
  772.   Go(YMIN,XMIN);
  773.   NextField(0);
  774. }
  775. void do_HPBLOCKMODE() {
  776.   Session->term->bool_hpBlockMode = (Arg[0]&&1);
  777.   HPSetLocal();
  778. }
  779. void do_HPPAGEMODE() {
  780.   /* PageMode(1) LineMode(0) */
  781.   if (Arg[0]) do_HPPAGE(); else do_HPNOPAGE();
  782. }
  783. void do_HPPAGE() {
  784.   Session->term->bool_hpPageMode = 1;
  785.   HPSetLocal();
  786. }
  787. void do_HPNOPAGE() {
  788.   Session->term->bool_hpPageMode = 0;
  789.   HPSetLocal();
  790. }
  791.